unit uProtocol;

interface

uses
  uProtoBuf;

const
  KEY_LEN               = 8;
  DEFAULT_KEY: array[0..KEY_LEN-1] of byte = (174, 191, 86, 120, 171, 205, 239, 241);
  
const  
  U_LOGIN_GATEWAY       = 20001;
    
type
  TProtoBufMessage = class
  public
    procedure WriteToBuffer(writeBuf: TWritingBuffer); virtual;
    procedure WriteExternal(writeBuf: TWritingBuffer);
  end;

  TLoginReqMsg = class(TProtoBufMessage)
  public
    Key: string;
    EKey: array[0..KEY_LEN-1] of byte;
      
    procedure WriteToBuffer(writeBuf: TWritingBuffer); override;
  end;

implementation


{ TProtoBufMessage }

procedure TProtoBufMessage.WriteToBuffer(writeBuf: TWritingBuffer);
begin

end;

procedure TProtoBufMessage.WriteExternal(writeBuf: TWritingBuffer);
var
  tmpBuf: TWritingBuffer;
begin
  tmpBuf := TWritingBuffer.Create;
  WriteToBuffer(tmpBuf);
  tmpBuf.ToNormal(writeBuf);
  tmpBuf.Free;
end;

{ TLoginReqMsg }

procedure TLoginReqMsg.WriteToBuffer(writeBuf: TWritingBuffer);
var
  i: Integer;
  {$IFDEF DEBUG}
  deBuf: array[0..1024] of char;
  {$ENDIF}  
begin
  Inherited;
  TWriteUtiles.WriteTag(writeBuf, wtLengthDelimited, 2);
  TWriteUtiles.WriteString(writeBuf, Key);
  {$IFDEF DEBUG}
  FillChar(deBuf, Sizeof(deBuf), 0);
  Move(writeBuf.DataPtr^, debuf, writeBuf.Length);
  {$ENDIF}  
  for i := 0 to KEY_LEN - 1 do
  begin
    TWriteUtiles.WriteTag(writeBuf, wtVarint, 3);
    TWriteUtiles.WriteInt(writeBuf, EKey[i]);
  end;
end;

end.
